#include <normalButton.h>

//#include <string>
//using namespace std;

namespace lgb_gtk
{

  NormalButton::NormalButton()
  {
    x = 0;
    y = 0;
    width = 60;
    height = 30;
  }

  NormalButton::~NormalButton()
  {
    if(hasInit)
      gtk_widget_destroy(button);
  }
  
  int NormalButton::SetLabel(string value)
  {
    labelStr = value;
    if(hasInit)
      gtk_button_set_label((GtkButton*)button , labelStr.c_str());
    return 0;
  }

  int NormalButton::SetImages(string bg, string ig , string cg)
  {
    //std::cout<<"there are no SetImages() function in NormalButton class\n";
    return 0;
  }

  int NormalButton::Init()
  {
    if(hasInit)
      return 1;

    button = gtk_button_new();
    goo_canvas_widget_new(canvas , button , x , y , width , height , NULL);
    gtk_button_set_label((GtkButton*)button , labelStr.c_str());
    g_signal_connect(button , "button-press-event" , GCallback(ButtonPress) , this);
    g_signal_connect(button , "enter-notify-event" , GCallback(MouseOver) , this);
    g_signal_connect(button , "leave-notify-event" , GCallback(MouseOut) , this);

    hasInit = true;
    return 0;
  }
  
  gboolean ButtonPress(GtkWidget      *widget,
		       GdkEventButton *event,
		       gpointer        user_data)
  {
    NormalButton *btn = (NormalButton*) user_data;
    btn->MouseDownBaseFunction();
    return true;
  }

  gboolean MouseOver(GtkWidget        *widget,
                     GdkEventCrossing *event,
                     gpointer          user_data)
  {
    NormalButton *btn = (NormalButton*) user_data;
    btn->MouseOverBaseFunction();
    return true;
  }

  gboolean MouseOut(GtkWidget        *widget,
                    GdkEventCrossing *event,
                    gpointer          user_data)
  {
    NormalButton *btn = (NormalButton*) user_data;
    btn->MouseOutBaseFunction();
    return true;
  }

}
